<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * For example, it puts together the home page when no home.php file exists.
 *
 * @link http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); 
$query = new WP_Query('tag=hot-news&orderby=ID&order=DESC');
$hotnews = $query->get_posts();
$hot = $hotnews [0];
unset($query);
$query = new WP_Query('tag=hot-relate&orderby=ID&order=DESC');
$hotrelate = $query->get_posts();

$img = wp_get_attachment_url( get_post_thumbnail_id($hot->ID, 'thumbnail') );
if(!$img || $img =='')
$img = get_first_image($hot->post_content);

?>

	<div id="primary" class="site-content">
		<div id="content" role="main">
		<div id="main-top-col1">
			<div id="hot-news">
				<div class="hot-img">
					<a href="<?php echo get_permalink($hot->ID) ?>" title="<?php echo $hot->post_title; ?>">
					<img src="<?php echo $img;?>" alt="<?php echo $hot->post_title; ?>"/>
					</a>
				</div>
				<h3 class="hot-title"><a href="<?php echo get_permalink($hot->ID) ?>" title="<?php echo $hot->post_title; ?>"><?php echo $hot->post_title; ?></a></h3>
				<div class="hot-desc"><?php
				echo $hot->post_excerpt;
				//$t = explode('<!--more-->', $hot->post_content); echo strip_tags($t[0]); 
				
				?></div>
			</div>
			
			<ul id="relate-hot-news">
				<?php 
				$i = 0;
				if ($hotrelate)
				foreach ($hotrelate as $relate){ 
					if ($i >= 6)
						break;
					$i++;
					
					$img = wp_get_attachment_url( get_post_thumbnail_id($relate->ID, 'thumbnail') );
					if(!$img || $img =='')
						$img = get_first_image($relate->post_content);

					?>
				
				<li class="relate-hot-item-1">
					<a href="<?php echo get_permalink($relate->ID) ?>">
						<div class="relate-hot-img">
							<img src="<?php echo $img;?>" alt="" />
						</div>
						<h4 class="relate-hot-title"><?php echo $relate->post_title ; ?></h4>
					</a>
				</li>
				<?php } ?>
			</ul>
		</div>
		<div id="main-top-col2">
		<?php if ( is_active_sidebar( 'right-2' ) ) : ?>
			<div id="right-2" class="widget-area">
				<?php dynamic_sidebar( 'right-2' ); ?>
			</div>
		<?php endif; ?>
		</div>
		<div class="clear"></div>
	<?php 
	
	?>
		<div id="mid-box">
		<?php if ( is_active_sidebar( 'sidebar-3' ) ) : ?>
		<div id="sidebar-3">
			<?php dynamic_sidebar('sidebar-3'); ?>
		</div>
		<?php endif; ?>
		
		<?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?>
		<div id="sidebar-4">
			<?php dynamic_sidebar('sidebar-4'); ?>
		</div>
		<?php endif; ?>
		
		</div>
		<div class="clear"></div>
		 
		<div class="clear"></div>
		<div id="gallery-box">
			<div class="gallery-title box-title">
				Ảnh đẹp trong tuần
			</div>
			
			<?php if (function_exists('slideshow')) { slideshow($output = true, $gallery_id = 1, $post_id = false, $params = array()); } ?>
			
		</div>
		</div><!-- #content -->
	</div><!-- #primary -->
	<script type="text/javascript">
	// $(function (){
	// $('#gallery-box').sliderPi();
	// });
	</script>
<?php get_sidebar(); ?>
<?php get_footer(); ?>